package cn.wen233.order.api;

import cn.wen233.common.api.R;
import cn.wen233.common.infrustructure.exception.BaseException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletResponse;

/**
 * 异常处理 api
 *
 * @author wenei
 * @date 2021-06-08 8:54
 */
@RestControllerAdvice
public class ExceptionApi {

    @ExceptionHandler(BaseException.class)
    public R<?> exceptionHandler(BaseException e, HttpServletResponse response) {
        response.setStatus(HttpStatus.ACCEPTED.value());
        return R.failure(e.getMessage(), R.Status.FAILURE);
    }
}
